package com.qyl.http_upload.server;

import com.alibaba.fastjson.JSONObject;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Map;

public class FileServer {
    public static final int PORT = 8080;
    public static final String PATH = "E:\\";

    public void start() throws Exception {
        System.out.println("start...");
        //创建服务器端对象
        ServerSocket server = new ServerSocket(PORT);
        while(true) {
            try {
                Socket socket = server.accept();
                //创建文件输出流和网络输入流
                BufferedReader inReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//                String res = inReader.readLine();
                // 以下是服务器返回的数据
                System.out.println("**************** Server request ****************");
                String tmp = "";
                while ((tmp = inReader.readLine()) != null) {
                    // 解析服务器返回的数据，做相应的处理
//                    res += tmp;
                    System.out.println(tmp);
//                    if(tmp.startsWith("Connection")){
//                        break;
//                    }

                }
//                System.out.println("拿到的数据："+res);
                PrintWriter outWriter = new PrintWriter(socket.getOutputStream());
                outWriter.println("success");
                outWriter.flush();
                outWriter.close();
                inReader.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws Exception {
        new FileServer().start();
    }
}
